<template>
  <div class="pack">
    <el-form
      ref="ruleForm"
      :model="ruleForm"
      style="text-align: left"
      :inline="true"
      class="demo-form-inline"
      size="medium"
      label-width="65px"
    >
      <div
        v-for="(item, index) in ruleForm.productList"
        :key="index"
        class="form-data-item"
      >
      <div>{{item.name}}</div>
        <el-form-item
          label="IP地址"
          :prop="`productList.${index}.jfmsg`"
          :rules="rules"
        >
          <el-input v-model="item.jfmsg" placeholder="IP地址" />
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即创建</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'Array',
  data () {
    return {
      rules: [
        { required: true, message: '请输入活动名称', trigger: 'blur' },
        { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
      ],
      ruleForm: {
        productList: [
          {
            jfmsg: '',
            name: '123'
          },
          {
            jfmsg: '',
            name: '123'
          },
          {
            jfmsg: '',
            name: '123'
          }
        ]
      }
    }
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.$message.success('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="less" scoped>
.pack {
  width: 800px;
  margin: 30px auto;

  .form-data {
    &-item {
      display: flex;
      align-items: center;
    }
    &-operating {
      margin-top: -24px;
    }
  }
  .cust-el-icon {
    font-size: 20px;
    font-weight: bold;
    margin-left: 10px;
    cursor: pointer;
  }
}
</style>
